<template>
  <div class="order wrap-content">
    <div class="order-tt">
      我的订单
    </div>
    <div class="order-content"
         v-if="orderList.length>0">
      <ul class="order-item"
          v-for="v,i in orderList">
        <li class="td order-item-img">
          <img :src="v.img"
               :alt="v.title">
        </li>
        <li class="td order-item-tt">
          <div class="order-name">
            {{v.orderName}}
          </div>
          <div class="order-time">
            {{v.createTime}}
          </div>
          <div class="order-id">
            订单号 {{v.orderSeq}}
            <span class="copy-btn"
                  @click="copy"
                  :data-clipboard-text="v.orderSeq">复制</span>
          </div>
        </li>
        <!-- <li class="tdr order-item-sum">
          <div class="order-price">
            <span>
              ￥<i>{{v.totalPrices}}</i>
            </span>
          </div>
        </li> -->
        <li class="tdr order-item-amount">
          <div class="num">
            <div class="prd-number prd-select">
              共{{v.numbers}}件商品
            </div>
          </div>
        </li>
      </ul>
    </div>
    <div class="order-content"
         v-else>
      <no-item></no-item>
    </div>

  </div>
</template>

<script>
import { fetchOrderList } from '@/api/common'
import { getStore } from '@/utils/common'
import Clipboard from 'clipboard'
import NoItem from '@/components/NoItem'
export default {
  data() {
    return {
      orderList: [],
    }
  },
  mounted() {
    this.getOrder()
  },
  components: {
    NoItem,
  },
  methods: {
    async getOrder() {
      const userId = JSON.parse(getStore('loginInfo')).id
      const res = await fetchOrderList({
        userId: userId,
      })
      this.orderList = res.orderList
    },
    copy() {
      var clipboard = new Clipboard('.copy-btn')
      clipboard.on('success', (e) => {
        this.$message({
          message: '复制成功',
          type: 'success',
        })
        // 释放内存
        clipboard.destroy()
      })
      clipboard.on('error', (e) => {
        // 不支持复制
        console.log('该浏览器不支持自动复制')
        // 释放内存
        clipboard.destroy()
      })
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/theme/mixin';
.order {
  margin-top: 30px;
  &-tt {
    height: 20px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #0e1b2f;
    font-size: 16px;
    margin-bottom: 20px;
  }
  &-item {
    border-radius: 9px;
    border: 1px solid #c5c7cb;
    padding: 20px;
    box-sizing: content-box;
    margin-bottom: 20px;
    @include clearfix();
    .td {
      float: left;
      min-height: 60px;
      overflow: hidden;
    }
    .tdr {
      float: right;
      min-height: 60px;
      line-height: 60px;
      overflow: hidden;
    }
    &-img {
      img {
        display: block;
        width: 60px;
        height: 60px;
        border-radius: 3px;
      }
    }
    &-tt {
      width: 365px;
      font-size: 14px;
      color: $tt;
      margin-left: 20px;
    }
    &-amount {
      width: 150px;
      margin-left: 100px;
    }
    &-sum {
      width: 50px;
    }
  }
  &-name {
    font-size: 14px;
    color: #0e1b2f;
    margin-bottom: 5px;
  }
  &-time {
    font-size: 12px;
    color: #7f838a;
    margin-bottom: 12px;
  }
  &-time {
    font-size: 12px;
    color: #3e4651;
  }
  &-price {
    span {
      color: #d04a4a;
      font-size: 14px;
    }
    i {
      font-style: inherit;
      font-size: 16px;
    }
  }
  &-bottom {
    padding-bottom: 20px;
    border-bottom: 1px solid #dedede;
    @include clearfix();
  }

  .all-money {
    float: right;
    font-size: 20px;
    span {
      color: #d04a4a;
      font-size: 20px;
    }
    i {
      font-style: inherit;
      font-size: 30px;
    }
  }
  .cart-place {
    padding: 80px 0;
    @include clearfix();
  }

  .address-info {
    font-size: 16px;
    span {
      cursor: pointer;
      font-weight: 400;
      color: #1681f1;
    }
  }
  .place-btn {
    float: right;
    width: 130px;
    height: 40px;
    line-height: 40px;
    color: #fff;
    text-align: center;
    background: #d04a4a;
    border-radius: 6px;
    cursor: pointer;
  }
  .disable {
    background: #d2d4d6;
  }
  .copy-btn {
    cursor: pointer;
    color: #1880f1;
    text-decoration: initial;
  }
}
</style>